package com.bytedance.danmaku.render.engine.demo.utils

import android.content.Context
import com.bytedance.danmaku.render.engine.demo.base.App
import com.bytedance.danmaku.render.engine.render.draw.DrawItem

/**
 * Created by dss886 on 2021/07/07.
 */

const val DRAW_TYPE_ADVANCED = 2000

const val LAYER_TYPE_ROTATE = 2000
const val LAYER_TYPE_METEOR = 2001
const val LAYER_Z_INDEX_ROTATE = 2000
const val LAYER_Z_INDEX_METEOR = 2001

const val DIGG_STATE_NONE = 0
const val DIGG_STATE_OTHER_DIGG = 1
const val DIGG_STATE_SELF_DIGG = 2
const val DRAW_TYPE_DIGG = 2001
const val DRAW_TYPE_GRADIENT_TEXT = 2002
const val DRAW_TYPE_BORDER_TEXT = 2003
const val DRAW_TYPE_SIMPLE_ADVANCED = 2004
const val DRAW_TYPE_OFFICIAL_ADVANCED = 2005
const val DRAW_TYPE_AUTO_SIZE_BITMAP = 2006
const val DRAW_TYPE_AUTO_SIZE_TEXT = 2007
const val DRAW_TYPE_SIMPLE_HAS_STAR = 2008
const val DRAW_TYPE_HAS_EMPTY_TEXT = 2009
const val DRAW_TYPE_DIGG_EMPTY_TEXT = 2010
const val DRAW_TYPE_GRADIENT_CHANGE_DIGG = 2011
const val DRAW_TYPE_SIMPLE_DIGG = 2012
object DensityUtils {

    /**
     * 根据手机的分辨率从 dp 的单位 转成为 px(像素)
     */
    fun Context.dp2px(dpValue: Float): Int {
        val scale = resources.displayMetrics.density
        return (dpValue * scale + 0.5f).toInt()
    }

    /**
     * 根据手机的分辨率从 px(像素) 的单位 转成为 dp
     */
    fun Context.px2dp(pxValue: Float): Int {
        val scale = resources.displayMetrics.density
        return (pxValue / scale + 0.5f).toInt()
    }
    fun dp2px(dpValue: Float): Int {
        val scale = App.inst().resources.displayMetrics.density
        return (dpValue * scale + 0.5f).toInt()
    }

    /**
     * 根据手机的分辨率从 px(像素) 的单位 转成为 dp
     */
    fun px2dp(pxValue: Float): Int {
        val scale = App.inst().resources.displayMetrics.density
        return (pxValue / scale + 0.5f).toInt()
    }
    fun sp2px(spValue: Float): Int {
        val scaledDensity = App.inst().resources.displayMetrics.scaledDensity
        return (spValue * scaledDensity + 0.5f).toInt()
    }
}
